package com.example.webcomen.Controller;


import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.log.Log;
import com.example.webcomen.Common.AjaxResult;
import com.example.webcomen.Model.AddMessageFront;
import com.example.webcomen.Model.User;
import com.example.webcomen.Service.UpdateService;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.json.JsonParser;
import org.springframework.web.bind.annotation.*;

@RestController
public class EditController {

    @Autowired
    private UpdateService updateService;
    @PostMapping("edit/sign/{userId}")
    public AjaxResult editSign(@RequestBody User user, @PathVariable String userId){
        Log a=Log.get("info");
//212-242
        if (user!=null)
            a.info(user.getSign());
        AjaxResult ajaxResult=null;
        if (user!=null&&user.getSign()!=null&&userId!=null&&
                updateService.editSignById(Integer.parseInt(userId), user.getSign())) {
            ajaxResult = AjaxResult.success("成功","success");
        }else {
            ajaxResult=AjaxResult.error();
        }

        return ajaxResult;
    }
    @PostMapping("edit/status/{userId}")
    public AjaxResult editStatus(@RequestBody User user, @PathVariable String userId){
        Log a=Log.get("info");
//212-242
        if (user!=null)
            a.info(user.getSign());
        AjaxResult ajaxResult=null;
        if (user!=null&&user.getStatus()!=null&&userId!=null&&
                updateService.editStatusById(Integer.parseInt(userId), user.getStatus())) {
            ajaxResult = AjaxResult.success("成功","success");
        }else {
            ajaxResult=AjaxResult.error();
        }

        return ajaxResult;
    }

}
